'use strict';
module.exports = app => {
  const { STRING, INTEGER } = app.Sequelize;
    const Model = app.model.define(
      'comment',
      {
          id: {type: INTEGER, primaryKey: true, autoIncrement: true},
          consult_id: INTEGER,
          member_id: INTEGER,
          user_id: INTEGER,
          star: STRING(255),
          content: STRING(255),
          parent_id: INTEGER,
          owner: INTEGER,
      },
      {
          tableName: 'comment',
          timestamps: true, // 启用时间戳(createdAt, updatedAt)
          updatedAt: 'updated_time', // 不想要 updatedAt
          createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 created_at
      }
  );
    Model.associate = function() {
        app.model.Comment.belongsTo(app.model.Member, { foreignKey: 'member_id', targetKey: 'id' });
        app.model.Comment.belongsTo(app.model.OrderGoods, { foreignKey: 'order_id', targetKey: 'id', as: 'order' });
        // user
        app.model.Comment.belongsTo(app.model.User, { foreignKey: 'user_id', targetKey: 'id' });
    }
    return Model
};
